﻿using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using DBUtility;
using gfLibrary;
using IYAKASAPortal.Services;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;
using System.Threading;

namespace IYAKASAPortal.PrintAll
{
    public partial class PrintAuto_MotorYQ : System.Web.UI.Page
    {


        private ReportDocument document;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
        }

        protected override void OnInit(EventArgs e)
        {
            if (Request["Key"] != null && Request["Key"].ToString() != "")
            {
                BindReportData(Request["Key"].ToString());
            }
        }

        private void BindReportData(string strKey)
        {
            int dispatchID = Convert.ToInt32(strKey);
            Thread t = new Thread(() =>
            {
                string strContent = "window.open('" + string.Format("PrintAuto_AJRG.aspx?Key={0}", strKey) + "');";
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "uuu", strContent, true);
            });
            t.Start();


            string strPathAJ = Server.MapPath("~/rpt/CrystalReportAJSLC.rpt");

            SetCRDataSource setData = new SetCRDataSource();

            document = setData.BindAJMotor_ReportEx(strKey, strPathAJ, false);
            CRAJ.ReportSource = document;
            CRAJ.DataBind();
            CRAJ.RefreshReport();

        }


        protected override void OnUnload(EventArgs e)
        {
            if (document != null)
            {
                document.Dispose();
            }

            base.OnUnload(e);
        }
    }
}